//
//  SSDetailIntroduceCell.m
//  starspaceVR
//
//  Created by 曹端芹 on 17/9/14.
//  Copyright © 2017年 starspace. All rights reserved.
//

#import "SSDetailIntroduceCell.h"
#import "NSString+Size.h"

@interface SSDetailIntroduceCell ()

@property (nonatomic,strong) UILabel *contentL;

@end

@implementation SSDetailIntroduceCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}

- (void) setupUI {
    
    UIView *spare = [[UIView alloc] init];
    spare.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:spare];
    [spare mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(self.contentView);
        make.height.mas_equalTo(10);
    }];
    
    UILabel *intrL = [[UILabel alloc] init];
    intrL.text = @"介绍";
    intrL.font = kFont(15);
    intrL.textColor = [UIColor redColor];
    [self.contentView addSubview:intrL];
    [intrL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(10);
        make.top.mas_equalTo(spare.mas_bottom).mas_offset(5);
        make.size.mas_equalTo(CGSizeMake(40, 20));
    }];
    
    UIView *indexL = [[UIView alloc] init];
    indexL.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:indexL];
    CGFloat indexW = [intrL.text widthWithFont:kFont(15) constrainedToHeight:20];
    
    [indexL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(intrL.mas_bottom).mas_offset(2);
        make.size.mas_equalTo(CGSizeMake(indexW, 2));
    }];
}

- (void)setModel:(SSAppliDetailModel *)model {
    _model = model;
    if (model.content == nil) {
        model.cellHeight = 44;
    }else{
       
        self.contentL.text = model.content;
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.contentL.text];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle setLineSpacing:6.0f];
        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, self.contentL.text.length)];
        self.contentL.attributedText = attributedString;
        CGSize contentSize = [self.contentL.text boundingRectWithSize:CGSizeMake(kScreenWidth - 20, MAXFLOAT) options: NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} context:nil].size;
        self.contentL.frame = CGRectMake(10, 44, kScreenWidth - 20, contentSize.height);
        [self.contentL sizeToFit];
        [self.contentView addSubview:self.contentL];
    
        model.cellHeight = CGRectGetMaxY(self.contentL.frame) + 10;
        
    }
    
    
}

- (UILabel *)contentL {
    if (!_contentL) {
        _contentL = [[UILabel alloc] init];
        _contentL.font = kFont(12);
        _contentL.textColor = kRGBColor(38, 38, 38);
        _contentL.numberOfLines = 0;
    }
    return _contentL;

}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
